subroutine bagi_dua_1(fungsi, eps_mesin, eps, a, b, c)
	implicit none
	double precision fungsi, eps_mesin, eps, a, b, c, temp_fa, temp_fb, temp_fc,lebar,a_lama,b_lama
	character(LEN=13) selang
	integer*2 counter
	counter = 0
	!print
	write (*,98)
	write (*,99) "r", "a", "c", "b", "f(a)", "f(c)", "f(b)", "Selang Baru", "Lebarnya"
	write (*,98)
	do 
		c = (a+b)/2
		temp_fa = fungsi(a)
		temp_fb = fungsi(b)
		temp_fc = fungsi(c)
		a_lama = a
		b_lama = b
		if (abs(temp_fc).LT.eps_mesin) then
			a = c
			b = c
		else
			if ((temp_fa * temp_fc).LT.0) then
				b = c	! selang baru [a,c]
				selang = "   [a, c]"
			else
				a = c   ! selang baru [c,b]
				selang = "   [c, b]"				
			end if
		end if
		lebar = abs(a-b)
		
		!print
		write (*,100) counter, a_lama, c, b_lama, temp_fa, temp_fc, temp_fb,selang,lebar
		
		counter = counter + 1
		if (lebar.LT.eps) then
			exit
		end if
	end do
	write (*,98)
98  format(90("-"))	
99  format(2X,A,7X,A,9X,A,9X,A,7X,A,6X,A,6X,A,3X,A,3X,A)
100 format(I4,F10.6,F10.6,F10.6,F10.6,F10.6,F10.6,A,F10.6)
end

subroutine bagi_dua_2(fungsi, eps_mesin, galat, a, b, c)
	implicit none
	double precision fungsi, eps_mesin, galat, a, b, c, temp_fa, temp_fb, temp_fc,temp_galat,c_lama,a_lama,b_lama
	character(LEN=13) selang
	integer*2 counter
	counter = 0
	c_lama = 0
	!print
	write (*,98)
	write (*,99) "r", "a", "c", "b", "f(a)", "f(c)", "f(b)", "Selang Baru", "Galat"
	write (*,98)
	do 
		c = (a+b)/2
		temp_fa = fungsi(a)
		temp_fb = fungsi(b)
		temp_fc = fungsi(c)
		a_lama = a
		b_lama = b
		if (abs(temp_fc).LT.eps_mesin) then
			a = c
			b = c
		else
			if ((temp_fa * temp_fc).LT.0) then
				b = c	! selang baru [a,c]
				selang = "   [a, c]"
			else
				a = c   ! selang baru [c,b]
				selang = "   [c, b]"				
			end if
		end if
		temp_galat = abs((c-c_lama)/c)
		c_lama = c
		!print
		write (*,100) counter, a_lama, c, b_lama, temp_fa, temp_fc, temp_fb,selang,temp_galat
		
		counter = counter + 1
		if (temp_galat.LT.galat) then
			exit
		end if
	end do
	write (*,98)
98  format(90("-"))	
99  format(2X,A,7X,A,9X,A,9X,A,7X,A,6X,A,6X,A,3X,A,3X,A)
100 format(I4,F10.6,F10.6,F10.6,F10.6,F10.6,F10.6,A,F10.6)
end
